home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / x25 / nrs.shar.Z / nrs.shar / nrs.hPRIME < prev    next >
Encoding:
Text File  |  1990-04-27  |  12.3 KB  |  423 lines

  1. #ifndef lint
  2. static char NrsId[] = "@(#)$Header: nrs.SH,v 3.2 87/06/24 18:13:44 pb Rel $";
  3. #endif lint
  4.  
  5. /* Copyright 1986, Piete Brooks, Julian Onions & Adrian Pell
  6.  *      pb@cl.cam.ac.uk, jpo@hcig.nott.ac.uk, Adrian.R.Pell@reading.ac.uk
  7.  *
  8.  * This program may be copied as long as you don't remove this notice,
  9.  * try to make any money off of it, or pretend that you wrote it.
  10.  */
  11.  
  12. #include    <stdio.h>
  13. #include    <ctype.h>
  14.  
  15. /* Define one of these if needed */
  16. /* #undef    VMS21        /* VAX VMS C 2.1 (used in nrs.h & misc)    */
  17. #define    PRIME        /* PR1ME                */
  18. /* #undef    VOID        /* V7 doesn't understand (void)        */
  19.  
  20. /* #undef    index    strchr
  21. /* #undef    USE_GETHOSTNAME        /* Use BSD gethostname() */
  22. /* #undef    USE_UNAME        /* Use USG uname()    */
  23.  
  24. /* Options .... */
  25. #define    F_YORK        /* york output format enabled */
  26. #define    F_X25HOSTS    /* /etc/x25hosts format    */
  27. #define    F_MMDF        /* mmdf format enabled    */
  28. #define    F_TEXT        /* text format enabled    */
  29. #define    F_SMAIL        /* reading sendmail format */
  30. #define    F_VMS        /* vms format enabled    */
  31. #define    F_SENDMAIL    /* UK sendmail format    */
  32. #define    F_DBM1        /* ucl dbm format */
  33. #define    F_PRIME        /* generate PRIME format .. what else ?? */
  34. #define    F_EDTEXT    /* Edinburgh text format */
  35.  
  36. /* #undef    MMDF_CHAN_BOTH_FORMS    /* Long AND short in mmdf.chan tables ?    */
  37.  
  38. /* Dependant info ... */
  39. #ifdef PRIME
  40. # include    <time.h>
  41. # define    off_t    Header
  42. # define    time_t    struct tm
  43. # define    static_f
  44. # define    universaluse(x)    (char *) (x)
  45. # define    universaldec(x)    char * x;
  46. #ifdef    UNIX
  47. UNIX on a PR1ME ?? If so, delete this line.
  48. #endif    UNIX
  49. #else    PRIME
  50. # include    <sys/types.h>
  51. #endif PRIME
  52.  
  53. #ifdef    VMS21
  54. # include    <stat.h>    /* For time_t        */
  55. # define exit_rc(x)    (!x)    /* lowest bit SET -> OK */
  56. # undef  UNIX            /* This ain't UNIX !    */
  57. #else VMS21
  58. # define noshare
  59. #endif    VMS21
  60.  
  61. #ifndef    VOID
  62. # define VOID (void)
  63. #endif    VOID
  64.  
  65. #ifndef static_f
  66. # define    static_f    static
  67. #endif static_f
  68. #ifndef    universaldec
  69. # define    universaldec(x)
  70. # define    universaluse(x)    x
  71. #endif    universaldec
  72. #ifndef    exit_rc
  73. # define exit_rc(x)    x
  74. #endif    exit_rc
  75.  
  76. #define    warn0(f)        warn_3(f, universaluse(0), universaluse(0), universaluse(0))
  77. #define    warn1(f, a1)        warn_3(f, universaluse(a1), universaluse(0), universaluse(0))
  78. #define    warn2(f, a1, a2)    warn_3(f, universaluse(a1), universaluse(a2), universaluse(0))
  79. #define    warn3(f, a1, a2, a3)    warn_3(f, universaluse(a1), universaluse(a2), universaluse(a3))
  80.  
  81. #define    fatal0(f)        fatal_2(f, universaluse(0), universaluse(0))
  82. #define    fatal1(f, a1)        fatal_2(f, universaluse(a1), universaluse(0))
  83. #define    fatal2(f, a1, a2)    fatal_2(f, universaluse(a1), universaluse(a2))
  84.  
  85. #define    vprintf0(n, f)     vprintf_3(n, f, universaluse(0), universaluse(0), universaluse(0))
  86. #define    vprintf1(n, f, a1)     vprintf_3(n, f, universaluse(a1), universaluse(0), universaluse(0))
  87. #define    vprintf2(n, f, a1, a2)     vprintf_3(n, f, universaluse(a1), universaluse(a2), universaluse(0))
  88. #define    vprintf3(n, f, a1, a2, a3)     vprintf_3(n, f, universaluse(a1), universaluse(a2), universaluse(a3))
  89.  
  90. # define    TRUE        1
  91. # define    FALSE        0
  92. # define    UNSET        -1    /* not yet set to anything    */
  93. # define    KEEPOPEN    01    /* keep file open        */
  94. # define    GETFNUMBER    02    /* file has a file number    */
  95. # define    SEEKFNUMBER    04    /* file number must be sought */
  96. # define    MAXQUADS    40    /* max quads we can cope with    */
  97. # define    MOD2        "MODULE2"    /* default module2 name */
  98. # define    MOD3        "MODULE3"    /* default module3 name */
  99. # define    MOD4        "MODULE4"    /* default module4 name */
  100. # define    DERFIL_D1    "DERFIL2"    /* default number 1    */
  101. # define    DERFIL_D2    "DERFIL1"    /* default number 2    */
  102. # define    MAXNAMELEN    128    /* generally large string    */
  103. # define    MAXAR        10    /* max application relays    */
  104. # define    MAXDESC        10    /* max description lines    */
  105. # define    TAGSIZE        6    /* size of tag in atomic files    */
  106. # define    MAXTABLES    40    /* maximum atomic files in table*/
  107. # define    MAXDOMAINS    20    /* maximium domains for mmdf    */
  108. # define    MAXLOCDOMAINS    20    /* max loc domains for york    */
  109. # define    MAGIC        '$'    /* magic char in comments    */
  110. # define    DCONTEXTS    10    /* Max number of domain contexts*/
  111.  
  112. /* atomic files fields */
  113. # define    DT        1    /* dte stuff        */
  114. # define    YB        2    /* Yellow book        */
  115. # define    AR        3    /* application relay    */
  116. # define    DI        4    /* description        */
  117.  
  118. /* long and the short of it */
  119. # define    LONG        1    /* long name    */
  120. # define    SHORT        2    /* short name    */
  121. # define    FORWARD        3    /* map forwards    */
  122. # define    REVERSE        4    /* map reverse    */
  123. # define    MIXED        5    /* mixed case    */
  124. # define    LOWER        6    /* lower case    */
  125. # define    IGNORERELAY    7    /* ignore application relay strings --
  126.                      * e.g. in VMS still generate entry */
  127.  
  128. /* Contexts that we're interested in */
  129. # define    X29        1    /* x29 context */
  130. # define    TS29        2
  131. # define    NIFTP        3    /* ftp blue book context */
  132. # define    MAIL_NIFTP    4    /* grey book mail context */
  133. # define    MAIL_X29    5
  134. # define    MAIL_TELEX    6
  135. # define    JTMP        7
  136. # define    JTMP_FILES    8
  137. # define    JTMP_REG    9
  138. # define    YBTS_NODE    10
  139. # define    YBTS        11
  140. # define    DESC        12
  141. # define    MAXCONTEXTS    (DESC+1)
  142.  
  143. /* the networks */
  144. # define    PSS        1
  145. # define    JANET        2
  146. # define    TELEX        3
  147. # define    MAXSUBNETS    (TELEX+1)
  148.  
  149. # define    max(X,Y)    ((X) < (Y)? (Y) : (X))
  150. # define    min(X,Y)    ((X) > (Y)? (Y) : (X))
  151.  
  152. typedef    short /*int*/ small;    /* V7: remove int ?? */
  153.  
  154. /* structure of the Module2 file */
  155. typedef struct mod2 {
  156.     int    index_disp;    /* index into module4    */
  157.     int    ls_disp;    /* index into module2    */
  158.     small    ls;        /* long/short flag    */
  159.     small    length;        /* length of string    */
  160.     char    name[MAXNAMELEN];    /* the string    */
  161. } Mod2;
  162.  
  163. /* structure of the module3 file (unused) */
  164. typedef struct mod3 {
  165.     small    m3_context;
  166.     small    m3_network;
  167.     small    m3_direction;
  168.     int    l_disp;
  169.     char    m3_dte[MAXNAMELEN];
  170.     char    m3_ybts[MAXNAMELEN];
  171. /*    char    m3_desc[MAXNAMELEN];    */
  172.     small    m3_length;
  173.     char    m3_string[MAXNAMELEN];
  174. } Mod3;
  175.  
  176. /* The quad structure */
  177. typedef struct Quad {
  178.     small    fnumb;    /* the file number to find it in    */
  179.     int    ngtwys;    /* the no. of gateways (what the hell is this?)    */
  180.     int    disp;    /* the displacement in the file        */
  181.     small    nlines;    /* the number of lines in the file    */
  182. } Quad;
  183.  
  184. /* structure of the module4 file */
  185. typedef struct mod4 {
  186.     small    nquads;    /* the number of quads    */
  187.     Quad    quads[MAXQUADS];    /* the quads */
  188. } Mod4;
  189.  
  190. /* the file header - one for each file */
  191. typedef struct Header {
  192.     int    H_nlines;    /* no. of lines in file    */
  193.     int    fnumber;    /* the file number    */
  194.     long    *offset;    /* lines to seek values    */
  195. } Header;
  196.  
  197. typedef    struct    Table {
  198.     char    *T_name;    /* the file name        */
  199.     small    T_context;    /* the context            */
  200.     small    T_network;    /* the network            */
  201.     small    T_direction;    /* the direction        */
  202.     Header    hdr;        /* The header for the file    */
  203. } Table;
  204.  
  205. #define    DIR_FORWARDS    1
  206. #define    DIR_REVERSE    2
  207. #define    MAXDIRECTIONS    (DIR_REVERSE+1)
  208.  
  209.  
  210. /* structure for the atomic file    */
  211. typedef    struct    atomic {
  212.     char    *dte;        /* The dte string    */
  213.     char    *ybts;        /* the yb string    */
  214.     char    *desc[MAXDESC];    /* the description    */
  215.     small    n_descs;    /* number of desc's    */
  216.     small    n_relays;    /* number of ar's    */
  217.     char    *ar[MAXAR];    /* the application relays    */
  218.     small    context;    /* what context this is in    */
  219.     small    network;    /* which subnet this is on    */
  220.     small    direction;    /* which direction this is    */
  221. } Atomic;
  222.  
  223. typedef struct    domain {    /* domain information (DERFIL2 only) */
  224.     char    name[MAXNAMELEN];    /* name of domain */
  225.     char    gateway[MAXNAMELEN];    /* gateway name or address */
  226.     int    n_contexts;        /* number of contexts */
  227.     int    contexts[DCONTEXTS];    /* contexts */
  228. } Domain;
  229.  
  230. typedef    struct    lookup {    /* struct used by lookup() routines */
  231.     char    *str;
  232.     int    value;
  233. } Lookup;
  234.  
  235. typedef struct version {
  236.     int    hours;
  237.     int    minutes;
  238.     int    day;
  239.     int    month;
  240.     int    year;
  241.     int    format;
  242. } Version;
  243.  
  244. /* structure of the list of localdomains */
  245. typedef struct l_list {
  246.     int    len;        /* length of the string    */
  247.     char    *string;    /* the string        */
  248. } L_list;
  249.  
  250. Header    Module2;    /* info on the module 2 file */
  251. Header    Module3;    /* info on the module 4 file */
  252. Header    Module4;    /* info on the module 4 file */
  253. Header    Domains;    /* info on the domains file */
  254. Version    thisversion;    /* the current database version */
  255.  
  256. extern    Table    tablist[];    /* the table of files */
  257. extern    Lookup    contexts[];    /* list of contexts */
  258. extern    Lookup    netnames[];    /* list of networks */    
  259. extern    Lookup    lc_netnames[];    /* list of networks in lower case */    
  260. extern    Lookup    netabbrevs[];    /* network abbreviations */
  261. extern    Lookup    directions[];    /* list of directions */
  262. #ifdef    F_YORK
  263. extern    Lookup    def_ybstring[];    /* list of default  yb service names    */
  264. extern    Lookup    imp_services[];    /* list of implicit yb service names    */
  265. extern    Lookup    exp_services[];    /* list of explicit yb service names    */
  266. #endif    F_YORK
  267. #ifdef    F_YORK21
  268. #ifndef    F_YORK
  269. extern    Lookup    def_ybstring[];    /* list of default  yb service names    */
  270. #endif    F_YORK
  271. extern    Lookup    exp_21services[]; /* list of explicit yb service names    */
  272. #endif    F_YORK21
  273. #ifdef    F_VMS
  274. extern    Lookup    vms_services[];    /* list of vms context name        */
  275. #endif    F_VMS
  276. #ifdef    F_DBM1
  277. #define    DBSEP        '\034'
  278.  
  279. #define    R_MAIN        '#'
  280. #define    R_ALIAS        '>'
  281. #define    R_REV        '$'
  282. #define    R_DOMAIN    '@'
  283.  
  284. #define    DEF_MAXFTP    50
  285. #define    DEF_LOCAL    0
  286. #define    DEF_OLD        0
  287. #define    DEF_DISABLED    0
  288. #endif    F_DBM1
  289. #ifdef    F_PRIME
  290. int    primeformat();
  291. #endif    F_PRIME
  292.  
  293. Mod2    *getm2rec();
  294. Mod3    *getm3rec();
  295. Mod4    *getm4rec();
  296. Atomic    *getatrec();
  297. Table    *gettab();
  298. char    *vlookup();
  299. char    *lowerfy();
  300. FILE    *getfp();
  301. int    noformat();
  302.  
  303. # ifdef    F_YORK
  304. int    yorkformat();
  305. #define    COLON    ((char) (':' | 0x80))
  306. # endif    F_YORK
  307.  
  308. # ifdef    F_X25HOSTS
  309. int    x25hostsformat();
  310. # endif    F_X25HOSTS
  311.  
  312. # ifdef    F_MMDF
  313. int    mmdfformat();
  314. int    mmdfdomain();
  315. #define FLIP
  316. #define MULT_OUTPUT_FILES
  317. # endif    F_MMDF
  318.  
  319. # ifdef    F_TEXT
  320. int    textformat();
  321. # endif    F_TEXT
  322.  
  323. # ifdef    F_VMS
  324. int    vmsm4rec();
  325. int    vmsformat();
  326. # endif    F_VMS
  327.  
  328. # ifdef    F_EDTEXT
  329. int    edtextm4rec();
  330. int    edtextformat();
  331. int    edtextdomain();
  332.  
  333. #define    FL_CNTX    4    /* Width of the first field (context)        */
  334. #define    FL_NET    1    /* Width of network field            */
  335. #define    FL_DOM    10    /* Width of domain name (in domain section)    */
  336. #define    FL_PREF1    18    /* Width of "shortform" prefix        */
  337. #define    FL_PREF2    22    /* Width of "longform" prefix        */
  338.  
  339. #define    O_ED_MASK    0x0007
  340. #define    O_ED_LONG    0x0004
  341. #define    O_ED_SHORT    0x0002
  342. #define    O_ED_SIMPLE    0x0001
  343. #define    O_ED_DEFAULT    O_ED_SHORT
  344. # endif    F_EDTEXT
  345.  
  346. # ifdef    F_SMAIL
  347. int    smailformat();
  348. # endif    F_SMAIL
  349.  
  350. # ifdef    F_SENDMAIL
  351. int    sendmailformat();
  352. int    sendmaildomain();
  353. #define FLIP
  354. #define MULT_OUTPUT_FILES
  355. # endif    F_SENDMAIL
  356.  
  357. # ifdef    F_YORK21
  358. int    york21m4rec();
  359. #  ifndef    COLON
  360. #define    COLON    ((char) (':' | 0x80))
  361. #  endif    COLON
  362. extern    L_list    localdomains[]; /* local domains    */
  363. # endif    F_YORK21
  364.  
  365. #ifdef    F_DBM1
  366. int    dbm1m4rec();
  367. int    dbm1format();
  368. int    dbm1domain();
  369. #endif    F_DBM1
  370.  
  371. # ifdef    MULT_OUTPUT_FILES
  372. # define    LOCAL    01
  373. # define    USED    02
  374.  
  375. typedef    struct file_list {
  376.     char    *dname;        /* domain name - short form        */
  377.     char    *ldname;    /* domain name - long form        */
  378.     char    *fname;        /* the file associated with above    */
  379.     small    net;        /* the associated network if any    */
  380.     small    flags;        /* various flags - see above        */
  381. } File_list;
  382.  
  383. extern    File_list fil_list[];    /* list of mmdf domains & channels    */
  384. extern    char    *relay_host;    /* relay host to janet            */
  385. #endif    MULT_OUTPUT_FILES
  386.  
  387. extern    char    *calloc();
  388. extern    char    *strdup();
  389. extern    char    *strcpy();
  390. extern    char    *strncpy();
  391. extern    char    *strcat();
  392. extern    char    *malloc();
  393. extern    char    *index();
  394. extern    char    *getfpath();
  395. extern    int    (*outputm4rec)();  /* output a complete m4 record */
  396. extern    int    (*outputformat)();
  397. extern    int    (*outputdomain)(); /* output a domain record */
  398.  
  399. extern    char    *invo_name;    /* the prog name (argv[0]) */
  400. extern    int    trip2fnumb[MAXCONTEXTS][MAXSUBNETS][MAXDIRECTIONS];
  401.                 /* Map triple to file number    */
  402. extern    int    max_fnumb;    /* the max file number we've got*/
  403. extern    int    ignore_relay;    /* ignore application relay strings --
  404.                  * e.g. in VMS still generate entry */
  405. extern    int    verbose;    /* verbosity level        */
  406. extern    int    forwrev;    /* forward/reverse lookup    */
  407. extern    int    longshort;    /* is long or short form used ?    */
  408. extern    int    mixlow;        /* mixed/lower case        */
  409. extern    int    usederfil;    /* use derived file             */
  410. extern    int    options;    /* output specific options    */
  411. extern    char    nullstring[];    /* The null string (no value)    */
  412. extern    char    *M2file;    /* the Module2 file name    */
  413. extern    char    *M3file;    /* the module3 file name    */
  414. extern    char    *M4file;    /* the module4 file name    */
  415. extern    char    *Derfile;    /* the derived file name        */
  416. extern    char    *DOMfile;    /* the domain file name        */
  417. extern    char    *janetgateway;    /* gateway to janet        */
  418. extern    char    *pssgateway;    /* gateway to pss        */
  419. extern    char    *directory;    /* the unix directory for files */
  420. extern    char    *stripoff;    /* strip off this prefix in output */
  421. extern    char    *hostname;    /* the name of this host    */
  422. extern    char    *commentfile;    /* the file with comments in     */
  423.